from asyncio import gather

import pytest
import os
from common.Yaml import Yaml
from common.Request import Request
from common.Path import project_path
import allure
filepath=project_path()
#读取common.yaml文件,headers,base_url等信息
common_yaml_file=os.path.join(filepath,"common", "common.yaml")
common_yaml_data = Yaml(common_yaml_file).read_yaml()
headers=common_yaml_data['headers']
base_url=common_yaml_data['base_url']
#读取仓位新增yaml文件
wam_pos_add_yaml_file=os.path.join(filepath,"api", "warehouse", "wam_pos_add.yaml")
wam_pos_add_yaml_data = Yaml(wam_pos_add_yaml_file).read_yaml()
wam_pos_add_test_cases=wam_pos_add_yaml_data['test_cases']
#读取仓库新增yaml文件
wah_add_yaml_file=os.path.join(filepath,"api", "warehouse", "warehouse_add.yaml")
wah_add_add_yaml_data = Yaml(wah_add_yaml_file).read_yaml()
wah_add_test_cases=wah_add_add_yaml_data['test_cases']




#实例化域名
req=Request(base_url)

@allure.feature("仓库相关接口测试")

#参数化案例
@pytest.mark.parametrize("wam_pos_add_test_case",wam_pos_add_test_cases)
#@allure.title("{test_case['story']}")

#新增仓位
def test_wam_pos_add(wam_pos_add_test_case):
        allure.dynamic.story(wam_pos_add_test_case['story'])
        allure.dynamic.title(wam_pos_add_test_case['story'])
        json_dict = wam_pos_add_test_case['data']

    #title=test_case['story']
        response=req.send_request(method=wam_pos_add_test_case['method'],url=base_url+wam_pos_add_test_case['url'],json=json_dict,headers=headers).json()

    #print(f"正在执行测试: {title}")
        assert response['data']==wam_pos_add_test_case['expected_data']
#参数化案例
@pytest.mark.parametrize("wah_add_test_case",wah_add_test_cases)
#新增仓库
def test_wah_add(wah_add_test_case):
        allure.dynamic.story(wah_add_test_case['story'])
        allure.dynamic.title(wah_add_test_case['story'])
        json_dict = wah_add_test_case['data']

        # title=test_case['story']
        response = req.send_request(method=wah_add_test_case['method'], url=base_url + wah_add_test_case['url'],
                                    json=json_dict, headers=headers).json()

        # print(f"正在执行测试: {title}")
        assert response['data'] == wah_add_test_case['expected_data']


if __name__ == '__main__':
    pytest.main(["-s","-v","Test_warehouse.py"])


